import Vue from 'vue'
import Router from 'vue-router'

import ShouYe from '@/views/ShouYe'
import FenLei from '@/views/FenLei'
import GouWu from '@/views/GouWu'
import WoDe from '@/views/WoDe'
import Detail from '@/views/Detail'
import Login from '@/views/Login'
import Register from '@/views/Register'
import YanZheng from '@/views/YanZheng'
import BianJi from '@/views/BianJi'
import Swipdetail from '@/views/Swipdetail'


Vue.use(Router)

var router= new Router({
  routes: [
    {
      path: '/',
      name: 'ShouYe',
      component: ShouYe
    },
    {
      path: '/FenLei',
      name: 'FenLei',
      component: FenLei
    },
    {
      path: '/GouWu',
      name: 'GouWu',
      component: GouWu
    },
    {
      path: '/WoDe',
      name: 'WoDe',
      component: WoDe
    },
    {
      path: '/Detail',
      name: 'Detail',
      component: Detail
    },
    {
      path: '/Login',
      name: 'Login',
      component: Login
    },
    {
      path: '/Register',
      name: 'Register',
      component: Register
    },
    {
      path: '/YanZheng',
      name: 'YanZheng',
      component: YanZheng
    },
    {
      path: '/BianJi',
      name: 'BianJi',
      component: BianJi
    },
    {
      path: '/Swipdetail',
      name: 'Swipdetail',
      component: Swipdetail
    },
    
    

  ]
});
  router.beforeEach((to, from, next) => {
    if (to.path=="/Login" || to.path=="/Register" || to.path=="/WoDe" || to.path=="/YanZheng") {
      next();
    }else{
      if(sessionStorage.getItem("token")){
            next()
        }else{
          next("/Login")
        }
    }
    

  })

export default router;
